<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="../lib/angular.js"></script>
    <script src="../lib/angular-route.js"></script>
    <script type="text/javascript">
        angular.module('myApp',['ngRoute'])
                .factory('GithubService',['$q','$http',function($q,$http){
                    var getPullRequests=function(){
                        var defferred=$q.defer();
                        $http.get('https://api.github.com/repos/angular/angular.js/pulls')
                                .success(function(data){
                                    defferred.resolve(data);
                                })
                                .error(function(reason){
                                    defferred.reject(reason);
                                });
                        return defferred.promise;
                    };
                    return {
                        getPullRequests:getPullRequests
                    }
                }])
                .controller('DashboardCtrl',['$scope','GithubService',
                    function($scope,UserService){
                        //GithubService的getPullRequests()方法，返回一个promise
                        UserService.getPullRequests().then(function(data){
                           $scope.pullRequests=data.data;
                       });
                    }])
    </script>
</head>
<body ng-app="myApp">
<h1>Open Pull Requests for AngularJS</h1>
<ul ng-controller="DashboardCtrl">
    <li ng-repeat="pr in pullRequests">
        {{pr.title}}
    </li>
</ul>
</body>
</html>